package store.controller;

import store.dao.SupplierDAO;
import store.po.Supplier;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/supplier/add")
public class AddSupplier extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Supplier s=new Supplier();
        s.setName(request.getParameter("name"));
        s.setContacts(request.getParameter("contacts"));
        s.setTel(request.getParameter("tel"));
        s.setInfo(request.getParameter("info"));
        try {
            new SupplierDAO().save(s);
            request.getRequestDispatcher("/supplier/list").forward(request,response);
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException(e.getMessage());
        }
    }
}
